﻿#region Copyright & License
//
// Copyright 2010 sd&c Hofmann 
// 
// mailto:info@sdch.de
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using SDCH.SharePoint.Log4Sandbox.UserCode;
using System.Web.UI.HtmlControls;

namespace SDCH.SharePoint.Log4Sandbox.TestWP.HelloProxy
{
    [ToolboxItemAttribute(false)]
    public class HelloProxy : WebPart
    {
        protected TextBox txtInput;
        protected Label lblResult;
        protected Button cmdSend;
        protected LogContext mLog;

        public HelloProxy()
        {
            mLog = LogContextManager.GetLogContext(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        }

        protected override void CreateChildControls()
        {
            Label lbl = new Label();
            lbl.Text = "This is the log4Sandbox test webpart. Please tip a message and press send.";
            this.Controls.Add(lbl);

            this.Controls.Add(new HtmlGenericControl("br"));
            
            txtInput = new TextBox();
           this.Controls.Add(txtInput);

           this.Controls.Add(new HtmlGenericControl("br"));

            cmdSend = new Button();
            cmdSend.Text = "Send";
            cmdSend.Click += new EventHandler(cmdSend_Click);
            this.Controls.Add(cmdSend);

            this.Controls.Add(new HtmlGenericControl("br"));

            lblResult = new Label();
            this.Controls.Add(lblResult);

            
        }

        void cmdSend_Click(object sender, EventArgs e)
        {
            
            mLog.Debug(txtInput.Text);
            mLog.Debug(txtInput.Text, new Exception(txtInput.Text + " Exception"));
            mLog.Warn(txtInput.Text);
            mLog.Warn(txtInput.Text, new Exception(txtInput.Text + " Exception"));
            mLog.Error(txtInput.Text);
            mLog.Error(txtInput.Text, new Exception(txtInput.Text + " Exception"));
            mLog.Fatal(txtInput.Text);
            mLog.Fatal(txtInput.Text, new Exception(txtInput.Text + " Exception"));
            mLog.Info(txtInput.Text);
            mLog.Info(txtInput.Text, new Exception(txtInput.Text + " Exception"));
        }


    }
}
